package com.socket.server;

import com.socket.server.utils.DefaultConstants;
import com.socket.server.utils.NettyServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;
import java.net.InetSocketAddress;

/**
 * @ProjectName: netty_socket
 * @Package: com.socket.server
 * @ClassName: ${CLASS_NAME}
 * @Author: xiahuihui
 * @Description: ${description}
 * @Date: 2020/6/10 0010 13:38
 * @Version: 1.0
 */
@SpringBootApplication
public class SocketApplication implements CommandLineRunner {

    @Resource
    private NettyServer nettyServer;



    private Logger log = LogManager.getLogger(getClass());

    public static void main(String[] args) {
        SpringApplication.run(SocketApplication.class,args);

    }

    @Override
    public void run(String... args) throws Exception {
//        asyncTask.stringTask("执行周期任务！！！！");
        InetSocketAddress address = new InetSocketAddress(DefaultConstants.SOCKET_IP,DefaultConstants.SOCKET_PORT);
        log.info("netty服务已启动！！！！地址："+DefaultConstants.SOCKET_IP);
        nettyServer.start(address);
//        System.out.println(Thread.currentThread().getName()+"-----"+i);


//        ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
//        InetSocketAddress address = new InetSocketAddress(DefaultConstants.SOCKET_IP,DefaultConstants.SOCKET_PORT);
//        log.info("netty服务已启动！！！！地址："+DefaultConstants.SOCKET_IP);
//        nettyServer.start(address);
//        cachedThreadPool.execute(new Runnable() {
//            @Override
//            public void run() {
//
//                //
//                System.out.println("开始启动周期任务！！！！");
//
//            }
//        });


    }
}
